package com.sneakxy.cloudbase.platform.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.sneakxy.cloudbase.platform.bean.dto.AccountDTO;
import com.sneakxy.cloudbase.platform.shiro.ShiroAccount;

public class SecurityShiroService implements IShiroService {

	@Autowired
	private AccountClient accountClient;
	
	@Autowired
	private RoleClient roleClient;
	
	@Autowired
	private PermissionClient permissionClient;
	
	@Override
	public ShiroAccount findShiroAccount(Object principal, String host) {
		return AccountDTO.to(accountClient.account((String) principal, host).getData());
	}

	@Override
	public List<String> findRoles(ShiroAccount account) {
		return roleClient.roles(account.getId()).getData();
	}

	@Override
	public List<String> findPermissions(ShiroAccount account, List<String> roles) {
		return permissionClient.permissions(roles).getData();
	}

}
